package cn.chmcyz.bootredis.datainit;

import cn.chmcyz.bootredis.filter.RedisBloomFilter;
import cn.chmcyz.bootredis.mapper.EmployeeMapper;
import cn.chmcyz.bootredis.model.Employee;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class RedisDataInit {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private RedisBloomFilter redisBloomFilter;

    @PostConstruct
    public void dataInit(){
        List<Employee> employees = employeeMapper.selectList(new LambdaQueryWrapper<Employee>().le(Employee::getId, 6000).gt(Employee::getId,5001));
        List<Integer> idList = employees.stream().map(Employee::getId).collect(Collectors.toList());
        System.err.println("放入缓存的员工信息"+idList);
        idList.forEach(id ->{
            redisBloomFilter.put("" + id);
        });
    }

}
